<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            list-style-type: none;
            margin: 0 0;
            padding: 0 0;
        }
        body {
            background-image: url('../images/desktop_1.jpg');
        }
        .box {
            background-color: pink;
            width: 320px;
            height: 50px;
            margin: 100px auto;
        }
        .box ul {
            display: flex;
        }
        .box ul li {
            width: 80px;
            height: 50px;
            background-size: 80px 50px;
        }
    </style>
</head>
<body>
    <div class="box">
        <ul>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <script>
        var lis = document.querySelectorAll('li');
        //循环设置li的图片
        for (var i = 0; i < lis.length; i++) {
            var index = i + 1
            lis[i].style.backgroundImage = 'url(' + '../images/desktop_' + index + '.jpg' +')';
            lis[i].onclick =  function() {
                //1.获取body对象
                var bodyTmep = document.body;
                //把当前li的图片路径赋值给body
                bodyTmep.style.backgroundImage = this.style.backgroundImage;
            }
        }
        
    </script>
</body>
</html>